# 自由课题, 大家按自己的想法, 将身边的事物抽象出一个类, 并创建多个实例
# 自定义类属性和方法练习

class Animal(object):
    subject='animal'
    language='jaosheng'#类属性
    busy=True#类属性
    __baobei=['ligndang','maozi']#私有属性
    game=None#实例属性

    def __init__(self,obj,hairs):
        self.p=obj
        self.__hairs=hairs#实例的私有属性

    def show_type(self):
        print("i am animal")

    @classmethod
    def get_case(cls):  # 类方法,仅供类调用的方法
        return cls.__baobei  # 通过类方法获得类的私有属性

    @classmethod#类方法
    def __new__(cls, *args, **kwargs):
        print('init class 类方法')
        return super().__new__(cls)

    def __str__(self):#__str接口；改变了print函数的打印输出方式
        return f"My Dict {self.busy}"

print("调用类方法@classmethod， def get_case(cls):返回类的一个私有属性： ")
print(Animal.get_case())

print(Animal)  #<class '__main__.Animal'>
print(Animal.language)#访问类属性
print(Animal._Animal__baobei)#访问私有属性
ani = Animal("anima1","hairs1")
ani.game='ani_game'
print(ani.game)#fw访问实例属性
print(ani._Animal__hairs)#实例的私有属性

print(ani)  #<__main__.Animal object at 0x000002419E826400>
print(ani.p)

ani2 = Animal("anima2","hairs2")
print(ani2)  #<__main__.Animal object at 0x000002419E826400>
print(ani2.p)


class Dog(Animal):
    def __init__(self,name,calls):
        self.name=name
        self.calls = calls
    def displayCall(self):
        print("my calls is:", self.calls)


class Cat(Animal):
    def __init__(self,name,calls):
        self.name=name
        self.calls = calls
    def displayCall(self):
        print("my calls is:" ,self.calls)

dog=Dog("dog","wangwang")
cat=Cat("cat","miaomiao")
print(dog.name)
print(cat.name)
dog.displayCall()
cat.displayCall()
dog.show_type()

